# Makefile

# Object files for the examples
OBJS_TIMER=example_timer.o asm.o debug.o
OBJS_UART=example_uart.o asm.o
OBJS_SYSCALL=example_syscall.o asm.o syscall.o debug.o

# Project directory
PROJECT_DIR=/it/kurs/compsys/HT2004/

# GCC prefix
MIPS_PREFIX=/it/kurs/compsys/mips-devel/bin/mips-idt-elf

# gcc flags for the MIPS architecture:
#  -EL     : Little endian
#  -G0     : Always use small data (using register gp)
#  -mips32 : Compile for a 32-bit MIPS architecture
#
ARCH=-EL -G0 -mips32

# Other gcc flags
CFLAGS	+= -ggdb -Wall -Werror -I$(PROJECT_DIR)/include

# Compiler and linker commands
CC=$(MIPS_PREFIX)-gcc
LD=$(MIPS_PREFIX)-ld -Ttext 80020000

SIMICS=/home/${USER}/simics-workspace

# Defines how object files (*.o) are created from C files (*.c)
%.o: %.c
	$(CC) $(ARCH) $(CFLAGS) -o $@ -c $<

# Defines how object files (*.o) are created from assembler files (*.S)
%.o: %.S
	$(CC) $(ARCH) $(CFLAGS) -o $@ -c $<

# Default: build all examples
all: examples

# Build all examples
examples: example_timer example_uart example_syscall

# Build the timer example
example_timer: $(OBJS_TIMER)
	$(LD) $(ARCH) -o example_timer $(OBJS_TIMER)

# Build the UART example
example_uart: $(OBJS_UART)
	$(LD) $(ARCH) -o example_uart $(OBJS_UART)

run: malta_try
	./scripts/run.sh $(SIMICS) $<

# Build the syscall example
example_syscall: $(OBJS_SYSCALL)
	$(LD) $(ARCH) -o example_syscall $(OBJS_SYSCALL)

# clean: remove object files and emacs backup files
clean:
	rm -f *.o *~



